<!DOCTYPE html>
<html>

<head>
	<% include global/meta.html %>
		<% include global/top-css.html %>
			<title>yuscms</title>
</head>

<body>

	<!--main-->
	<main class="main" data-info="<%=admin.permission%>">

		<div class="ys-admin-pos c-a1a3aa">
			首页
			<span class="f-sum">></span>
			<span class="c-565b6d">站点信息</span>
		</div>

		<div class="ys-admin-tablist">
			<div class="ys-admin-tab-header row justify-content-b">
				<p class="f-14 c-565b6d pl-8 pt-6"></p>
			</div>

			<div class="mr-10 ml-10">
				<form @submit.prevent="checkForm" name="form">
					<ul>

						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">网站名称</label>
							</div>
							<div class="col-10">
								<input type="text" name="webname" class="input" placeholder="网站名称" v-model="params.webname" />
							</div>
						</li>

						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">关&nbsp; 键&nbsp; 词</label>
							</div>
							<div class="col-10">
								<input type="text" name="keyword" placeholder="网站关键字" class="input" v-model="params.keyword" />
							</div>
						</li>


						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">描　　述</label>
							</div>

							<div class="col-10">
								<input type="text" name="description" placeholder="当前网站的描述信息" class="input" v-model="params.description" />
							</div>
						</li>

						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">网站网址</label>
							</div>

							<div class="col-10">
								<input type="text" name="weburl" placeholder="当前网站的域名" class="input" v-model="params.weburl" />
							</div>
						</li>

						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">站长邮箱</label>
							</div>

							<div class="col-10">
								<input type="text" name="email" placeholder="站长邮箱方便联系" class="input" v-model="params.email" />
							</div>
						</li>

						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">站点版权</label>
							</div>

							<div class="col-10">
								<input type="text" name="copyright" placeholder="版权信息或备案号" class="input" v-model="params.copyright" />
							</div>
						</li>

						<li class="row pd-10 f-14">
							<div class="col-hd">
								<label class="label">站点统计</label>
							</div>

							<div class="col-10">
								<textarea name="code" placeholder="用于统计代码调用" class="textarea c-666" v-model="params.code"></textarea>
							</div>
						</li>


						<li class="pd-10 mt-15">
							<div class="col-hd">
								&nbsp;&nbsp;&nbsp;&nbsp;
							</div>
							<div class="col-bd row ml-35">
								<input name="send" class="btn btn-sure ml-35" type="submit" value="确 定" />
							</div>
						</li>

					</ul>

				</form>
			</div>
		</div>
	</main>

	<% include global/all-js.html %>
		<script>
			var vm = new Vue({
				el: '.main',
				data: {
					level: [],
					params: {
						webname: "",
						keyword: "",
						description: "",
						weburl: "",
						email: "",
						copyright: "",
						code: "",
						id: ""
					}
				},
				methods: {

					query() {
						let _this = this;
						axios
							.get("/api/admin/web/query")
							.then(data => {
								let filterData = data.data;
								if (filterData.success && filterData.data.length > 0) {
									_this.params = filterData.data[0];
								} else {
									tipsWarn(filterData.msg);
								}
							})
							.catch(error => {
								console.log(error);
							});
					},

					webUpdate() {
						let _this = this;
						axios
							.post("/api/admin/web/update", _this.params)
							.then(data => {
								let filterData = data.data;
								if (filterData.success && filterData.data.affectedRows === 1) {
									tips(_this, "更新成功");
									_this.$router.go(-1);
								} else {
									tipsWarn(_this, filterData.msg);
								}
							})
							.catch(error => {
								console.log(error);
							});
					},

					checkForm() {
						let _this = this;
						if (!hasPermission("1")) {
							tipsWarn(_this, "对不起,您没有操作权限^_^");
							return;
						}

						let fm = document.form;

						if (_this.params.webname == "") {
							tipsWarn(_this, "网站名称不能为空！");
							fm.webname.focus();
							return false;
						}

						if (_this.params.keyword == "") {
							tipsWarn(_this, "网站关键词不能为空！");
							fm.keyword.focus();
							return false;
						}

						if (_this.params.description == "") {
							tipsWarn(_this, "网站描述不能为空！");
							fm.description.focus();
							return false;
						}

						if (_this.params.email != "" && !$m.isEmail(_this.params.email)) {
							tipsWarn(_this, "请正确填写邮箱^_^");
							fm.email.focus();
							return false;
						}

						if (_this.params.weburl == "") {
							tipsWarn(_this, "网址不能为空！");
							fm.weburl.focus();
							return false;
						}

						if (_this.params.copyright == "") {
							tipsWarn(_this, "版权不能为空");
							fm.copyright.focus();
							return false;
						}

						this.webUpdate();
					}
				},
				created: function () {
					this.query();
				},
				mounted: function () {
				},
				updated: function () {
				}
			});
		</script>
</body>

</html>